package kmi.droid.particles.sample;

import kmi.droid.animatron.Particle;
import kmi.droid.animatron.Vector2;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;

public class SquareParticle extends Particle
{
	private int color;

	public SquareParticle(Vector2 pos, int color, float mass)
	{
		super();

		this.setPosition(pos);
		this.setColor(color);
		this.Mass = mass;
	}

	public int getColor()
	{
		return color;
	}

	public void setColor(int color)
	{
		this.color = color;
	}

	@Override
	public void draw(Canvas canvas)
	{
		Paint squarePaint = new Paint();
		squarePaint.setColor(color);

		Path square = SquareHelper.getSquare(getPosition().X, getPosition().Y,
				100, 100, Angle);

		canvas.drawPath(square, squarePaint);
	}

	public void invalidate(Vector2 touchPoint)
	{
		float distance = Vector2.distance(this.getPosition(), touchPoint);

		this.AngleVelocity = distance * 0.0002f;
		;

		if (distance > 0)
		{
			Vector2 diff = Vector2.subtract(touchPoint, this.getPosition());

			this.Acceleration = Vector2.multiply(diff.getNormal(), 0.000004f
					* distance / this.Mass);

			this.Velocity = Vector2.multiply(this.Velocity,
					1 / (1 + 0.0005f * this.Mass));
		}
	}

	@Override
	public boolean getIsAlive()
	{
		return true;
	}
}